package mk.jug.academy.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Lob;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity modeling a registered user ({@link Student}, {@link Lecturer}, {@link Supporter} or {@link Sponsor}s)'s entry content.
 *
 * @author Ice.Penov
 */
@Entity
public class Content extends RootEntity {
	
	public static final String CODE_PREFIX = "CON-";	
	
	@Column(nullable = false)
	private String title;
	
	@Column(nullable = false) @Lob
	private String body;
	
	@Column(nullable = false) @Temporal(TemporalType.TIMESTAMP)
	private Date publishDate;
	
	@Column
	private String creatorDisplayName;
	
	@Column
	private Long creatorID;
	
	@Column @Enumerated(EnumType.STRING)
	private UserType creatorType;
	
	@Column @Enumerated(EnumType.STRING)
	private ContentStatus status;
	
	@Column 
	private Integer numberOfComments;

	/**
	 * The code identifier of the entity. 
	 */	
	public String getCode() {
		return CODE_PREFIX + getId();
	}
	
	/**
	 * Returns the title.
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * Setter for the title.
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * Returns the body.
	 */
	public String getBody() {
		return body;
	}

	/**
	 * Setter for the body.
	 */
	public void setBody(String body) {
		this.body = body;
	}

	/**
	 * Returns the publishDate.
	 */
	public Date getPublishDate() {
		return publishDate;
	}

	/**
	 * Setter for the publishDate.
	 */
	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}

	/**
	 * Returns the userID.
	 */
	public Long getCreatorID() {
		return creatorID;
	}

	/**
	 * Setter for the userID.
	 */
	public void setCreatorID(Long userID) {
		this.creatorID = userID;
	}

	/**
	 * Returns the userType.
	 */
	public UserType getCreatorType() {
		return creatorType;
	}

	/**
	 * Setter for the userType.
	 */
	public void setCreatorType(UserType userType) {
		this.creatorType = userType;
	}

	/**
	 * Returns the userDisplayName.
	 */
	public String getCreatorDisplayName() {
		return creatorDisplayName;
	}

	/**
	 * Setter for the userDisplayName.
	 */
	public void setCreatorDisplayName(String userDisplayName) {
		this.creatorDisplayName = userDisplayName;
	}

	/**
	 * Returns the status.
	 */
	public ContentStatus getStatus() {
		return status;
	}

	/**
	 * Setter for the status.
	 */
	public void setStatus(ContentStatus status) {
		this.status = status;
	}

	/**
	 * Returns the numberOfComments.
	 */
	public Integer getNumberOfComments() {
		if (numberOfComments == null) {
			return 0;
		}
		return numberOfComments;
	}

	/**
	 * Setter for the numberOfComments.
	 */
	public void setNumberOfComments(Integer numberOfComments) {
		this.numberOfComments = numberOfComments;
	}
	
	/**
	 * Convenience method for increasing the number of comments, for this content.
	 */
	public void increaseNumberOfComments() {
		if (numberOfComments == null) {
			numberOfComments = 0;
		}
		numberOfComments++;
	}
	
	/**
	 * Convenience method for decreasing the number of comments, for this content.
	 */
	public void decreaseNumberOfComments() {
		if (numberOfComments == null) {
			numberOfComments = 0;
		}
		numberOfComments--;
	}
	
}